import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * alwaysShow: true               if set true, will always show the root menu
 *                                if not set alwaysShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
    roles: ['admin','editor']    control the page roles (you can set multiple roles)
    title: 'title'               the name show in sidebar and breadcrumb (recommend set)
    icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
    breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
    activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
  }
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      name: 'Dashboard',
      component: () => import('@/views/dashboard/index'),
      meta: { title: 'Dashboard', icon: 'el-icon-orange' }
    }]
  },

  {
    path: '/org',
    component: Layout,
    redirect: '/org/orglist',
    name: 'org',
    meta: { title: '机构管理', icon: 'el-icon-ice-cream' },
    children: [
      {
        path: 'orglist',
        name: 'orglist',
        component: () => import('@/views/org/list'),
        meta: { title: '机构列表', icon: 'el-icon-grape' }
      },
      {
        path: 'orgadd',
        name: 'orgadd',
        hidden: true,
        component: () => import('@/views/org/listadd'),
        meta: { title: '新增机构', icon: 'el-icon-grape' }
      },
      {
        path: 'orglistclick',
        name: 'orglistclick',
        hidden: true,
        component: () => import('@/views/org/orglistclick'),
        meta: { title: '查看机构列表', icon: 'el-icon-grape' }
      },
      {
        path: 'orgupdate',
        name: 'orgupdate',
        hidden: true,
        component: () => import('@/views/org/orgupdate'),
        meta: { title: '修改机构列表', icon: 'el-icon-grape' }
      },
      {
        path: 'fundlist',
        name: 'fundlist',
        hidden: true,
        component: () => import('@/views/org/fundlist'),
        meta: { title: '机构财政拨款', icon: 'el-icon-grape' }
      },
      {
        path: 'fundupdate',
        name: 'fundupdate',
        hidden: true,
        component: () => import('@/views/org/fundupdate'),
        meta: { title: '机构财政拨款', icon: 'el-icon-grape' }
      },
      {
        path: 'sectionlist',
        name: 'sectionlist',
        component: () => import('@/views/section/list'),
        meta: { title: '科室列表', icon: 'el-icon-grape' }
      },
      {
        path: 'sectionadd',
        name: 'sectionadd',
        hidden: true,
        component: () => import('@/views/section/sectionadd'),
        meta: { title: '科室创建', icon: 'el-icon-grape' }
      },
      {
        path: 'sectionupdateandclick',
        name: 'sectionupdateandclick',
        hidden: true,
        component: () => import('@/views/section/components/sectionupdateandclick'),
        meta: { title: '科室更新', icon: 'el-icon-grape' }
      },
      {
        path: 'money',
        name: 'money',
        component: () => import('@/views/statistics/money'),
        meta: { title: '年度财政拨款情况表', icon: 'el-icon-grape' }
      },
      {
        path: 'device',
        name: 'device',
        component: () => import('@/views/statistics/device'),
        meta: { title: '仪器设备情况表', icon: 'el-icon-grape' }
      },
      {
        path: 'orginfo',
        name: 'orginfo',
        component: () => import('@/views/statistics/orginfo'),
        meta: { title: '监督机构基本情况表', icon: 'el-icon-grape' }
      },

    ]
  },
  {
    path: '/personnel',
    component: Layout,
    redirect: '/personnel/personnellist',
    name: 'personnel',
    meta: { title: "人员管理", icon: 'el-icon-sugar'},
    children: [
      {
        path: 'personnellist',
        name: 'personnellist',
        component: () => import('@/views/personnel/personnellist'),
        meta: { title: '人员列表', icon: 'el-icon-apple'}
      },
      {
        path: 'personadd',
        name: 'personadd',
        hidden: true,
        component: () => import('@/views/personnel/personadd'),
        meta: { title: '人员创建', icon: 'el-icon-apple'}
      },
      {
        path: 'personscan',
        name: 'personscan',
        hidden: true,
        component: () => import('@/views/personnel/personoperate/personscan'),
        meta: { title: '人员查看', icon: 'el-icon-apple'}
      },
      {
        path: 'personupdate',
        name: 'personupdate',
        hidden: true,
        component: () => import('@/views/personnel/personoperate/personupdate'),
        meta: { title: '人员更新', icon: 'el-icon-apple'}
      },
      {
        path: 'sectionrelevance',
        name: 'sectionrelevance',
        hidden: true,
        component: () => import('@/views/personnel/personoperate/sectionrelevance'),
        meta: { title: '关联科室', icon: 'el-icon-apple'}
      },
      {
        path: 'empower',
        name: 'empower',
        hidden: true,
        component: () => import('@/views/personnel/empower'),
        meta: { title: '人员授权', icon: 'el-icon-apple'}
      },
      {
        path: 'empoweron',
        name: 'empoweron',
        hidden: true,
        component: () => import('@/views/personnel/empoweron'),
        meta: { title: '被授权人确定', icon: 'el-icon-apple'}
      },
      {
        path: 'managerlist',
        name: 'managerlist',
        component: () => import('@/views/personnel/managelist'),
        meta: { title: '所级领导名录管理', icon: 'el-icon-apple'}
      },
      {
        path: 'managescan',
        name: 'managescan',
        hidden: true,
        component: () => import('@/views/personnel/personoperate/managescan'),
        meta: { title: '领导名录详细信息', icon: 'el-icon-apple'}
      },
      {
        path: 'manageupdate',
        name: 'manageupdate',
        hidden: true,
        component: () => import('@/views/personnel/personoperate/manageupdate'),
        meta: { title: '修改领导名录信息', icon: 'el-icon-apple'}
      },
      {
        path: 'manageadd',
        name: 'manageadd',
        hidden: true,
        component: () => import('@/views/personnel/personoperate/manageadd'),
        meta: { title: '添加领导名录信息', icon: 'el-icon-apple'}
      },
      {
        path: 'lader',
        name: 'lader',
        component: () => import('@/views/statistics/lader'),
        meta: { title: '所级领导名录统计表', icon: 'el-icon-apple'}
      },
      {
        path: 'compose',
        name: 'compose',
        component: () => import('@/views/personnel/compose'),
        meta: { title: '人员构成情况表', icon: 'el-icon-apple'}
      },
      {
        path: 'healthsupervisiors',
        name: 'healthsupervisiors',
        component: () => import('@/views/personnel/healthsupervisiors'),
        meta: { title: '卫生监督员管理信息汇总', icon: 'el-icon-apple'}
      },
      {
        path: 'baseskill',
        name: 'baseskill',
        component: () => import('@/views/personnel/baseskill'),
        meta: { title: '专业技术人员基本情况表', icon: 'el-icon-apple'}
      },
      {
        path: 'administration',
        name: 'administration',
        component: () => import('@/views/personnel/administration'),
        meta: { title: '行政管理人员基本情况表', icon: 'el-icon-apple'}
      },
    ]
  },
  {
    path: '/account',
    component: Layout,
    redirect: '/loginnumebr/loginlist',
    name: 'loginnumber1',
    alwaysShow: true,
    meta: { title: '登录号管理', icon: 'el-icon-cherry'},
    children: [
      {
        path: 'loginnumber',
        name: 'loginnumber',
        component: () => import('@/views/loginnumber/loginlist'),
        meta: {title: '登录号列表', icon: 'el-icon-milk-tea'}
      }
    ]
  },

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
